﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Cn.Edwon.Web.Support;
using System.Reflection;
using Cn.Cellula.Biz.Port;
using Cn.Edwon.Spring;
using Cn.Cellula.Client.ControlHelper;
using System.Collections.Generic;
using Cn.Cellula.Model;
using Cn.Edwon.Web;
using Cn.Cellula.Biz;
using Cn.Cellula.Model.System;
using Cn.Cellula.Client;

namespace Cn.Cellula.Website.Admin.Content.Template {
    public partial class List : PageSupport {
        IUserBiz biz = BizFactory.Get<IUserBiz>();
        protected void Page_Load(object sender, EventArgs e) {
            if (!Page.IsPostBack) {
                InitForm();
                LoadEOList();
            }
        }

        private void LoadEOList() {
            String hql = " from TSysTemplateEO eo order by eo.UpdateDate desc ";
            IList<TSysTemplateEO> list = biz.Find<TSysTemplateEO>(hql);
            this.gvList.DataSource = list;
            this.gvList.DataBind();

        }

        private void InitForm() {
        }

        protected void btn_Query_Click(object sender, EventArgs e) {
            LoadEOList();
        }

        protected void btn_EOAdd_Click(object sender, EventArgs e) {
            Response.Redirect("Edit.aspx");
        }

        protected void btn_EOUpdate_Click(object sender, EventArgs e) {
            IList<String> keys = GvHelper.GetSelectedKey(ref this.gvList, ClientBiz.GRIDVIEW_ROW_CHECKBOX_ID);
            if (keys != null && keys.Count > 0) {
                Response.Redirect("Edit.aspx?id=" + keys[0]);
            } else {
                SiteInfo.Send(Page, TxtDef.ERROR, TxtDef.NoEditSelect);
                return;
            }

        }

        protected void btn_EODel_Click(object sender, EventArgs e) {
            IList<String> keys = GvHelper.GetSelectedKey(ref this.gvList, ClientBiz.GRIDVIEW_ROW_CHECKBOX_ID);
            if (keys != null && keys.Count > 0) {
                foreach (String k in keys) {
                    biz.Delete<TSysTemplateEO>(k);
                }
            } else {
                SiteInfo.Send(Page, TxtDef.ERROR, TxtDef.NoDelSelect);
                return;
            }
            BizFactory.Get<ILogBiz>().LogDelete("模板", keys.Count, this.Actor, Request);
            LoadEOList();
        }

        protected void gvList_PageIndexChanging(object sender, GridViewPageEventArgs e) {
            this.gvList.PageIndex = e.NewPageIndex;
            LoadEOList();
        }
    }
}
